home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / exec.swg / 0010_Redirection in DOS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-02  |  1.4 KB  |  69 lines

  1. {
  2. MARTIN AUSTERMEIER
  3.  
  4. > PKZIP Filename -Z < zipcomment
  5. > Is there any way to do this WithOUT calling COMSPEC For anothershell?
  6.  
  7. yes, but much more complicated than leaving the job to %comspec..
  8.  
  9. Before executing PKZIP, you have to
  10.  
  11.   * open a Text File
  12.   * get its handle (see TextRec); save it in - say - "newStdIn"
  13.   * then perform something like
  14.   if (newSTDIN <> 0) then begin
  15.     saveHandle[STDIN]:=DosExt.DuplicateHandle (STDIN);
  16.     DosExt.ForceDuplicateHandle (newSTDIN, STDIN);
  17.     created[STDIN]:=True;
  18.   end;
  19.   (DosExt.xx Routines and STDIN Const explained below)
  20.  
  21.   * Exec()
  22.   * Cancel redirections:
  23. }
  24.  
  25. Procedure CancelRedirections; { of ExecuteProgram }
  26. Var
  27.   redirCnt : Word;
  28. begin
  29.   For redirCnt := STDIN to STDOUT do
  30.   begin
  31.     if created[redirCnt] then
  32.     begin
  33.       DosExt.ForceDuplicateHandle(saveHandle[redirCnt], redirCnt);
  34.       DosExt.CloseHandle(saveHandle[redirCnt]);
  35.     end;
  36.   end;
  37. end;
  38.  
  39. Const
  40.   STDIN  = 0;
  41.   STDOUT = 1;
  42.   STDERR = 2;
  43.  
  44. Procedure CallDos; Assembler;
  45. Asm
  46.   mov Dos.DosError, 0
  47.   Int 21h
  48.   jnc @@Ok
  49.   mov Dos.DosError, ax
  50.  @@Ok:
  51. end;
  52.  
  53. Function DuplicateHandle(handle : Word) : Word;  Assembler;
  54. Asm
  55.   mov ah, 45h
  56.   mov bx, handle
  57.   call CallDos
  58.   { DuplicateHandle := AX; }
  59. end;
  60.  
  61. Procedure ForceDuplicateHandle(h1, h2 : Word); Assembler;
  62. Asm
  63.   mov ah, 46h
  64.   mov bx, h1
  65.   mov cx, h2
  66.   call CallDos
  67. end;
  68.  
  69.